package com.toe.commodity.webapi.controller;

import com.toe.commodity.webapi.service.impl.CommodityClassesTypeServiceImpl;
import com.toe.common.restful.JsonResult;
import com.toe.pojo.entity.commodity.CommodityClassesType;
import com.toe.pojo.vo.commodity.CommodityClassTypeVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 陶涛
 * @since 2022-07-19
 */
@RestController
@RequestMapping("/webapi/commodity-classes-type")
public class CommodityClassesTypeController {

    @Autowired
    CommodityClassesTypeServiceImpl commodityClassesTypeService;

    @GetMapping("/getCommodityClassType")
    @ApiOperation("查询课程类型")
    public JsonResult  getCommodityClassType(){
        List<CommodityClassTypeVO> commodityClassType = commodityClassesTypeService.getCommodityClassType();
        return JsonResult.ok("查询成功",commodityClassType);
    }

    @GetMapping("/addNewCommodityClassType")
    @ApiOperation("新增课程类型")
    public JsonResult addNewCommodityClassType(String classTypeName){
        commodityClassesTypeService.addNewCommodityClassType(classTypeName);
        return JsonResult.ok("新增成功");
    }

    @GetMapping("/deletedCommodityClassType/{id}")
    @ApiOperation("删除课程类型")
    public JsonResult deletedCommodityClassType(@PathVariable("id") Long id){
        commodityClassesTypeService.deletedCommodityClassType(id);
        return  JsonResult.ok("删除成功");
    }

    @GetMapping("/updateCommodityClassTypeName")
    @ApiOperation("修改课程类型")
    public JsonResult updateCommodityClassTypeName(CommodityClassesType commodityClassesType){
        commodityClassesTypeService.updateCommodityClassTypeName(commodityClassesType);
        return JsonResult.ok("修改完成");
    }

}

